package cn.edu.fzu.delivery.http;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.util.LinkedList;
import java.util.List;

public final class HttpClientFactory {

    private static final List<HttpClient> clients = new LinkedList<>();

    private HttpClientFactory() {
    }


    /** 默认使用 apache httpclient **/
    public static final HttpClient get(int connectTimeout, int readTimeout) {
        return getApacheHttpClient(connectTimeout, readTimeout);
    }


    public static final HttpClient getOkHttpClient(int connectTimeout, int readTimeout) {
        HttpClient client = new OkHttp((long) connectTimeout, (long) readTimeout, UTF_8);
        clients.add(client);
        return client;
    }


    public static final HttpClient getApacheHttpClient(int connectTimeout, int readTimeout) {
        HttpClient client = new ApacheHttpClient(connectTimeout, readTimeout, UTF_8);
        clients.add(client);
        return client;
    }


    public static void close() {
        for (HttpClient client : clients) {
            client.close();
        }
    }
}
